package tech.aistar.controller.center;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import tech.aistar.entity.*;
import tech.aistar.service.center.IUserInfoService;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created by 23827 on 2019/10/4.
 */
@Controller
@RequestMapping("/number")
public class CenterNumberController {

    @Autowired
    private IUserInfoService iUserInfoService;

    @RequestMapping("/list")
    public String number(Model model,Integer id,HttpSession session){

        Integer uid = (Integer) session.getAttribute("userId");
        UserInfo userInfo = iUserInfoService.findNumberById(uid);
        session.setAttribute("userInfo",userInfo);
        return "user/centerNumber";
    }

    @RequestMapping("/update")
    public String testUpdate(HttpServletRequest req,Model model,Integer id,HttpSession session)throws ServletException,IOException{

        //接受参数
        String telNumber = req.getParameter("telNumber");
        Integer user_id= (Integer) session.getAttribute("userId");
        UserInfo userInfo = new UserInfo();
        userInfo.setId(user_id);
        userInfo.setTelNumber(telNumber);
//        telNumber.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
        iUserInfoService.updateById(userInfo);
        return number(model,id,session);

    }
}
